package com.web.controller.basic;

import java.util.ArrayList;
import java.util.List;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.web.dao.entity.UserEty;

@Controller
@RequestMapping(value="/basic/UserController/")
public class UserController {

	@RequestMapping("searchUser.action")
	public @ResponseBody String searchUser() {
		try {
			List<UserEty> dataList = new ArrayList<UserEty>();
			
			for(int i = 0; i < 10; i++) {
				UserEty ety = new UserEty();
				ety.setUserId(i);
				ety.setEmail("sniciq@gmail.com");
				ety.setUserName("sniciq");
				ety.setPassword("psw");
				dataList.add(ety);
			}
			
			JSONArray dataArr = new JSONArray();
			dataArr.addAll(dataList);
			
			JSONObject retObj = new JSONObject();
			retObj.put("page", 1);
			retObj.put("total", 10);
			retObj.put("records", dataList.size());
			retObj.put("rows", dataArr);
			
			return retObj.toString();
		}
		catch (Exception e) {
			e.printStackTrace();
			return e.toString();
		}
	}
	
	@RequestMapping("searchUser_flex.action")
	public @ResponseBody String searchUser_flex() {
		try {
			List<UserEty> dataList = new ArrayList<UserEty>();
			
			for(int i = 0; i < 10; i++) {
				UserEty ety = new UserEty();
				ety.setUserId(i);
				ety.setEmail("sniciq@gmail.com");
				ety.setUserName("sniciq");
				ety.setPassword("psw");
				dataList.add(ety);
			}
			
			JSONObject retObj = new JSONObject();
			retObj.put("page", 1);
			retObj.put("total", 100);
			
			JSONArray dataArr = new JSONArray();
			for(UserEty ety : dataList) {
				JSONObject aRow = new JSONObject();
				aRow.put("id", ety.getUserId());
				aRow.put("cell", ety);
				dataArr.add(aRow);
			}
			retObj.put("rows", dataArr);
			return retObj.toString();
		}
		catch (Exception e) {
			e.printStackTrace();
			return e.toString();
		}
	}
}
